package ita.class1.group2.supermarket.customer.controller;

import ita.class1.group2.supermarket.common.annotation.Autowired;
import ita.class1.group2.supermarket.common.annotation.Component;
import ita.class1.group2.supermarket.common.annotation.RequestMapping;
import ita.class1.group2.supermarket.common.pojo.Page;
import ita.class1.group2.supermarket.common.util.JsonUtil;
import ita.class1.group2.supermarket.customer.dto.StoreDetailInfomation;
import ita.class1.group2.supermarket.customer.pojo.Product;
import ita.class1.group2.supermarket.customer.service.ProductService;
import ita.class1.group2.supermarket.customer.service.StoreInformationService;

import java.util.HashMap;
import java.util.Map;

@Component
public class ProductController {
    @Autowired
    private StoreInformationService storeInformationService;

    @Autowired
    private ProductService productService;

    @RequestMapping("/products")
    public Page<Product> products(String params) {
        //String sId = "e86942ead2f94b2090b03893e9122fd7";
        Map jsonmap = new HashMap<>();
        try {
            jsonmap = JsonUtil.json2map(params);
        } catch (Exception e) {
            e.printStackTrace();
        }
        int pageIndex  = (int) jsonmap.get("pageIndex");
        int pageCount  = (int) jsonmap.get("pageCount");
        String sId  = (String) jsonmap.get("sId");
        return productService.findProductsBySId(sId,pageIndex,pageCount);
    }

}


